package cn.yunhe.controller;

import java.util.ArrayList;
import java.util.List;

import cn.yunhe.dao.BookDao;
import cn.yunhe.daoImpl.BookDaoImpl;
import cn.yunhe.model.Book;
import net.sf.json.JSONArray;

public class BookAction extends BaseAction {

	private static final long serialVersionUID = 1L;

	private String keywords;
	private String result;

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	public void setKeywords(String keywords) {
		this.keywords = keywords;
	}

	public String getKeywords() {
		return keywords;
	}

	List<Book> bookList = new ArrayList<Book>();
	private BookDao bookDao = new BookDaoImpl();

	public String queryByBookName() {
		Book book = new Book();
		book.setBookName(keywords);
		bookList = bookDao.searchBook(book);
		/* getMapRequest().put("bookList", bookList); */
		JSONArray jo = JSONArray.fromObject(bookList);
		this.result = jo.toString();
		return SUCCESS;
	}

	public String queryByAuthor() {
		Book book = new Book();
		book.setAuthor(keywords);
		bookList = bookDao.searchBook(book);
		/* getMapRequest().put("bookList", bookList); */
		JSONArray jo = JSONArray.fromObject(bookList);
		this.result = jo.toString();
		return SUCCESS;
	}

	public String queryByPublisher() {
		Book book = new Book();
		book.setPublisher(keywords);
		bookList = bookDao.searchBook(book);
		/* getMapRequest().put("bookList", bookList); */
		JSONArray jo = JSONArray.fromObject(bookList);
		this.result = jo.toString();
		return SUCCESS;
	}
}
